# L -> E--> G --> B

# # 案例1

# x = 1
# def foo():
#     # x = 10
#     print("foo函数的x：", x)
#
# def bar():
#     y = 20
#     print(y)

# foo()
# print("全局", x)
# print("全局", y)


# 案例2

# x = 1
# y = 2

# def test01():
#     # x = 10
#
#     def test02():
#         x = 100
#         print("test02的x:", x)
#         # print(id)
#
#     test02()
#     print("hello test01")


# test01()
# print("全局", x)
# test02()


# 案例3


# def test(x, y):
#     print(x)
#     print(y)


# test(1, 2)
# x = 1
# y = 2
# test(x, y)

# 案例4

# def foo():
#     x = 10
#
#
# def bar():
#     y = 20
#     print(x)
#
# foo()
# bar()

# 案例5


# def get_pokes():
#     poke_types = ['♥️', '♦️', '♠️', '♣️']
#     poke_nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
#
#     print("=" * 40)
#     for p_type in poke_types:
#         for p_num in poke_nums:
#             print(f"{p_type}{p_num}", sep="\t", end="")
#         print()
#     print("=" * 40)
#
#
# get_pokes()
# get_pokes()
# get_pokes()

#  补充：global和 nonlocal关键字
# 案例1:
# x = 1
#
# def foo():
#     x = 10
#     print("foo的x：", x)
#
# foo()
# print("全局的x：", x)

# 案例2
# x = 1
# def sex_x():
#     global x
#     # print(id(x))
#     x = 100
#     print("sex_x的x：", x)
#
# # print(id(x))
# sex_x()
# print("全局的x：", x)


# nonlocal关键字


x = 10


def foo():
    x = 100
    print("foo的x的id：",id(x))

    def bar():
        # global x
        # 修改foo的x的值
        nonlocal x
        x = 1000
        print("bar的x的id：", id(x))
        # print("bar的x：", x)

    bar()
    # print("foo的x:", x)


foo()

# print("全局的x：", x)
